package com.sunsy.authserver.util;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author 孙思远
 * @time 2020/7/13
 */
public class Tools {

    public static boolean judgePhone(String phoneNumber){
        Pattern pattern = Pattern.compile("^[1]\\d{10}$");
        return pattern.matcher(phoneNumber).matches();
    }

    public static boolean judgeEmail(String email){
        if (null==email || "".equals(email)){
            return false;
        }
//        String regEx1 = "^([a-z0-9A-Z]+[_|-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";
        String regEx1="^[\u4e00-\u9fa5a-zA-Z0-9\\._-]+@[a-zA-Z0-9_-]+(\\.[a-zA-Z0-9_-]+)+$";
        Pattern p = Pattern.compile(regEx1);
        Matcher m = p.matcher(email);
        if(m.matches()){
            return true;
        }else{
            return false;
        }
    }

    /**
     * isNofilter  判断路径是否不需要过滤
     */
    public static boolean isNofilter(HttpServletRequest request, List<String> nofilter) {
        String requestURI = request.getServletPath();
        String match=".*(jpg|css|js|html|htm|png|ico)$";
        return nofilter.contains(requestURI) || requestURI.matches(match);
    }

}
